import { axios } from '@/api'

//获取尝试列表
export const getCity = () => {
  return axios.request({
    url: '/elm/lib/city-list@0.0.3/city_list.json'
  })
}

//获取金币商城的头部商品
export const getShopList = () => {
  return axios.request({
    url: '/act/activity/list?operatingActivityIds=135164955453121,135164836955956,135164756215681,135163795729171,135163665697681,135163596491731&pageNo=1&pageSize=50',
    method: 'get'
  })
}

//获取所有的金币商城商品
export const getAllShopList = () => {
  return axios.request({
    url: '/act/items/list?_=1599197355358&appItemIds=142251361585104%2C2152876%2C2087844%2C2000789%2C684271%2C2081161%2C2018812%2C2183089%2C1161758%2C1533566%2C1982298%2C1990013%2C1982301%2C1990012%2C2153913%2C2157305%2C2000802%2C1029043%2C2059672%2C2157306%2C2111343%2C1966537%2C2084759%2C2084762%2C2084766%2C2084769%2C2136106%2C2099479%2C2117729%2C2117730%2C2117731%2C2122345%2C2136164%2C2136472%2C2136475%2C2147088%2C1894301%2C2018799%2C1355960%2C1312305%2C1142165%2C818249%2C1847582%2C1888679%2C1932733%2C1942117%2C1828876%2C1819359%2C1819158%2C1807483%2C1693379%2C1476257&pageNo=1&pageSize=50&sort=custom&soldOutType=sink&showFlowRules=true&hiddenByDate=false',
    method: 'get'
  })
}

//获取发现头部

export const getFindHeader = data => {
  return axios.request({
    url: '/base/restapi/member/v1/discover?platform=1&block_index=0&latitude='+data.lat+'&longitude='+data.lng
  })
}

//获取限时抢购商品
export const limitData = () => {
  return axios.request({
    url: '/base/restapi/member/gifts/suggest',
    method: 'get'
  })
}

//获取定位周边优惠及规格
export const selectPosi = (latitude, longitude) => {
  return axios.request({
    url: `/base/pizza/shopping/restaurants/batch_filter?latitude=${latitude}&longitude=${longitude}&terminal=h5`,
    method: 'get'
  })
}

//获取详细地址1
export const getDetailAddress1 = (latitude, longitude, keyword) => {
  return axios.request({
    url: `/base/restapi/bgs/poi/search_poi_nearby_alipay?keyword=${keyword}&offset=0&limit=20&latitude=${latitude}&longitude=${longitude}`,
    method: 'get'
  })
}

//获取详细地址2
export const getDetailAddress2 = keyword => {
  return axios.request({
    url: `/base/restapi/bgs/poi/search_poi_nearby_alipay?keyword=${keyword}&offset=0&limit=20`,
    method: 'get'
  })
}

//获取周边商品信息
export const getAddrShopInfo = (latitude, longitude) => {
  return axios.request({
    url: `/base/restapi/shopping/v2/entries?latitude=${latitude}&longitude=${longitude}&templates[]=main_template&templates[]=favourable_template&templates[]=svip_template&terminal=h5`,
    method: 'get'
  })
}

//获取用户id
export const getUserId = () => {
  return axios.request({
    url: '/base/restapi/eus/v1/current_user?info_raw={}'
  })
}

//获取订单记录

export const getOrderList = userID => {
  return axios.request({
    url: '/base/restapi/bos/v2/users/'+userID+'/old_orders?limit=8&from_time='
  })
}

//获取当前订单状态

export const getOrdersStatus = ({userID, limit = 8, offset = 0}) => {
	return axios.request({
		url: '/base/restapi/bos/v2/users/'+userID+'/orders?limit='+limit+'&offset='+offset
	})
}

//获取登录的用户信息

export const getUserInfo = userID => {
  return axios.request({
    url: '/base/restapi/eus/v3/users/'+userID+'?'
  })
}

//获取我的地址

export const getMyAddress = userID => {
  return axios.request({
    url: '/base/restapi/member/v1/users/'+userID+'/addresses'
  })
}

//根据关键词搜索地址

export const searchAddr = keyword => {
  return axios.request({
    url: '/base/restapi/bgs/poi/search_poi_nearby?keyword='+keyword+'&offset=0&limit=20',
    method: 'get'
  })
}

//修改地址

export const editAddress = info => {
  return axios.request({
    url: '/base/restapi/member/v1/users/'+info.user_id+'/addresses/'+info.id,
    method: 'put',
    contentType:'text/plain',
    data: info
  })
}

//删除地址

export const removeAddress = info => {
  return axios.request({
    url: '/base/restapi/member/v1/users/'+info.user_id+'/addresses/'+info.id,
    method: 'delete'
  })
}

//新增地址

export const addAddress = info => {
  return axios.request({
    url: '/base/restapi/member/v1/users/'+info.user_id+'/addresses',
    contentType: 'text/plain',
    data: info,
    method: 'post'
  })
}

//发送绑定mobile验证码

export const sendValidCode = (userID, data) => {
  return axios.request({
    url: '/base/restapi/eus/v1/users/'+userID+'/mobile/mobile_send_code',
    method: 'post',
    contentType: 'text/plain',
    data
  })
}

//验证绑定mobile验证码

export const validationCode = (userID, data) => {
  return axios.request({
    url: '/base/restapi/eus/v1/users/'+userID+'/mobile/validate_old_mobile',
    method: 'post',
    contentType: 'text/plain',
    data
  })
}

//修改名称

export const changeUserName = (userID, data) => {
  return axios.request({
    url: '/base/restapi/eus/v1/users/'+userID+'/username',
    method: put,
    data
  })
}

//上传头像

export const uploadAvatar = (userID, file) => {
  return axios.request({
    url: '/base/restapi/eus/v1/users/'+userID+'/avatar',
    method: 'post',
    data: file,
    contentType: 'multipart/form-data'
  })
}

//获取图形验证码

export const getCaptchas = data => {
  return axios.request({
    url: '/base/restapi/eus/v3/captchas',
    method: 'post',
    data,
    contentType: 'text/plain'
  })
}

//获取金币

export const getCoin = userID => {
  return axios.request({
    url: '/base/restapi/member/v1/users/'+userID+'/coin/homepage'
  })
}

//获取自助客服数据

export const getKefuData = () => {
  return axios.request({
    url: '/help/meilin/homeConfig?scene=eleme-app-h5&orderId=&robotId=100131'
  })
}

//获取elm规则

export const eleRules = () => {
  return axios.request({
    url: '/elm/crayfish/services/agreement.js'
  })
}

//获取规则详细信息

export const getRulesDetails = key => {
  return axios.request({
    url: '/elm/crayfish/services/'+key
  })
}

//重新定位

export const rePosition = geo => {
  return axios.request({
    url: `/base/restapi/bgs/poi/reverse_geo_coding?latitude=${geo.latitude}&longitude=${geo.longitude}`
  })
}

//获取附件餐馆


export const getNearbyRestaurant = (data, params = '') => {
  data = Object.assign({
    latitude: '',
    longitude: '',
    limit: 8,
    offset: 0,
    order_by: ''
  }, data)
  return axios.request({
    url: `/base/restapi/shopping/v3/restaurants?latitude=${data.latitude}&longitude=${data.longitude}&offset=${data.offset}&limit=${data.limit}&extras[]=activities&extras[]=tags&extra_filters=home&order_by=${data.order_by}${params}&terminal=h5`
  })
}

//获取热门搜索

export const getHotSearch = geo => {
  return axios.request({
    url: `/base/restapi/swarm/v2/hot_search_words?latitude=${geo.latitude}&longitude=${geo.longitude}`
  })
}

//获取对应分类食品

export const getCateShop = req => {
  return axios.request({
    url: `/base/restapi/shopping/v2/foods_page/sift_factors?entry_id=${req.id}&longitude=${req.lng}&latitude=&{req.lat}&terminal=h5`
  })
}

//不感兴趣的餐馆

export const dislikeRestaurant = (resId, userID) => {
  return axios.request({
    url: '/base/restapi/ugc/v1/user/dislike/restaurant',
    data: {
      restaurant_id: resId,
      user_id: userID
    },
    contentType: 'application/json',
    method: 'post'
  })
}

//搜索附近餐馆

export const searchNearbyRestaurant = (keyword, cityId, geo) => {
  return axios.request({
    url: `/base/restapi/shopping/v1/typeahead?kw=${keyword}&latitude=${geo.latitude}&longitude=${geo.longitude}&city_id=${cityId}`
  })
}

//获取商家商品信息

export const getShopCommodity = data => {
  const random = Math.random()
  return axios.request({
    url: `/base/pizza/shopping/restaurants/${data.shopId}/batch_shop?user_id=${data.userID}&code=${random}&extras=%5B%22activities%22%2C%22albums%22%2C%22license%22%2C%22identification%22%2C%22qualification%22%5D&terminal=h5&latitude=${data.latitude}&longitude=${data.longitude}`
  })
}

//获取推荐商家

export const getRecommend = data => {
  data = Object.assign({
    offset: 0,
    limit: 15,
    keyword: '',
    latitude: '',
    longitude: '',
    search_item_type: 3,
    is_rewrite: 1
  }, data)
  return axios.request({
    url: `/base/restapi/shopping/v2/restaurants/search?offset=0&limit=15&keyword=${data.keyword}&latitude=${data.latitude}&longitude=${data.longitude}&search_item_type=${data.search_item_type}&is_rewrite=${data.is_rewrite}&extras[]=activities&extras[]=coupon&terminal=h5`
  })
}


//获取优惠券

export const getQuan = req => {
  const random = Math.random()
  return axios.request({
    url: `/base/restapi/shopping/v1/restaurants/${req.shopId}/exclusive_hongbao/detail?latitude=${req.latitude}&longitude=${req.longitude}&user_id=${req.userID}&code=${random}&terminal=h5`
  })
}

//会员专属特价商品

export const specialItemsForMembers = req => {
  const obj = {
    latitude: '',
    longitude: '',
    offset: 0,
    limit: 13
  }
  req = Object.assign(obj, req)
  return axios.request({
    url: `/base/restapi/shopping/v1/sale_list_index?latitude=${req.latitude}&longitude=${req.longitude}&type=supervip&offset=${req.offset}&limit=${req.limit}`
  })
}

//周边优惠券

export const nearbyQuan = req => {
  const obj = {
    userID: '',
    latitude: '',
    longitude: '',
    exchange_type: 3,
    offset: 0,
    limit: 30,
    platform: 1,
    source: 2
  }
  req = Object.assign(obj, req)
  return axios.request({
    url: `/base/restapi/member/v2/users/${req.userID}/supervip/missions/bonus/coupon?latitude=${req.latitude}&longitude=${req.longitude}&exchange_type=${req.exchange_type}&offset=${req.offset}&limit=${req.limit}&platform=${req.platform}&source=${req.source}`
  })
}

//获取会员页面详细信息

export const getMemberPageInfo = type => {
  const sell_hader =  Promise.resolve(axios.request({
    url: `/elm/crayfish/supervip-relife/sell-hader`
  }))
  const sell_button =  Promise.resolve(axios.request({
    url: `/elm/crayfish/supervip-relife/sell-button`
  }))
  const sell_1 =  Promise.resolve(axios.request({
    url: `/elm/crayfish/supervip-relife/sell-1`
  }))
  const sell_2 =  Promise.resolve(axios.request({
    url: `/elm/crayfish/supervip-relife/sell-2`
  }))
  const sell_3 =  Promise.resolve(axios.request({
    url: `/elm/crayfish/supervip-relife/sell-3`
  }))
  const sell_4 =  Promise.resolve(axios.request({
    url: `/elm/crayfish/supervip-relife/sell-4`
  }))
  const sell_5 =  Promise.resolve(axios.request({
    url: `/elm/crayfish/supervip-relife/sell-5`
  }))

  return Promise.allSettled([sell_hader, sell_button, sell_1, sell_2, sell_3, sell_4, sell_5])
}

//会员价格

export const membershipPrice = req => {
  return axios.request({
    url: `/base/restapi/member/v1/users/${req.userID}/supervip/sale?latitude=${req.latitude}&longitude=${req.longitude}&channel=app&product_id=default`
  })
}

//发送登录验证码

export const sendCodeLogin = data => {
  const obj = {
    captcha_hash: '',
    captcha_value: '',
    mobile: '',
    scf: 'ms'
  }
  data = Object.assign(obj, data)
  return axios.request({
    url: '/base/restapi/eus/login/mobile_send_code',
    contentType: 'application/json',
    method: 'post',
    data
  })
}

//验证登录验证码

export const validCodeLogin = data => {
  return axios.request({
    url: '/base/restapi/eus/login/login_by_mobile',
    contentType: 'application/json',
    method: 'post',
    data
  })
}
//获取商家评价

export const getRstComments = (data, f = true) => {
  data = Object.assign({
    shopId: '',
    offset:0,
    limit:20,
    shopId: '',
    lat: '',
    lng: '',
    has_content: true,
    tag_name: ''
  }, data)
  if(f) {
    return axios.request({
      url: '/base/pizza/ugc/restaurants/'+data.shopId+'/batch_comments?has_content='+data.has_content+'&tag_name='+data.tag_name+'&offset='+data.offset+'&limit='+data.limit,
      headers: {
        'x-shard': {
          shopid: data.shopId,
          loc: data.lat + ',' + data.lng
        }
      }
    })
  }
  return axios.request({
    url: '/base/restapi/ugc/v3/restaurants/'+data.shopId+'/ratings?has_content='+data.has_content+'&tag_name='+data.tag_name+'&offset='+data.offset+'&limit='+data.limit,
    headers: {
      'x-shard': {
        shopid: data.shopId,
        loc: data.lat + ',' + data.lng
      }
    }
  })
}

//结算框数据

export const cardClient = data => {
  data = Object.assign({
    add_on_type: 0,
    additional_actions: [],
    business_type: 0,
    come_from: 'mobile',
    entities: [[]],
    entities_with_ingredient: [[]],
    from: null,
    geohash: 'wkeztn1j1xwb',
    operating_sku_ids: [],
    packages: [[]],
    sub_channel: '',
    tying_sku_entities: [[]],
  }, data)
  return axios.request({
    url: '/base/restapi/booking/v1/cart_client',
    method: 'post',
    contentType: 'application/json',
    data,
    headers: {
      'x-shard': {
        shopid: data.shopId,
        loc: data.lat + ',' + data.lng
      }
    }
  })
}

//获取商铺营业资质

export const getBusQual = data => {
  return axios.request({
    url: '/base/restapi/shopping/v1/restaurants/'+data.shopId+'/business/qualification?latitude='+data.lat+'&longitude='+data.lng+'&terminal=h5'
  })
}

//获取分类数据

export const getCateData = data => {
  return axios.request({
    url: '/base/restapi/shopping/v2/foods_page/sift_factors?entry_id='+data.cateId+'&longitude='+data.lng+'&latitude='+data.lat+'&terminal=h5'
  })
}

//获取商铺分类
export const  getRstCate = data => {
  return axios.request({
    url: '/base/restapi/shopping/v2/restaurant/category?latitude='+data.latitude+'&longitude='+data.longitude
  })
}

//获取全部商品分类

export const getAllCate = data => {
  return axios.request({
    url: '/base/restapi/shopping/v2/restaurant/category?latitude='+data.latitude+'&longitude=' + data.longitude
  })
}

//获取cookie

export const getCookie = () => {
  return axios.request({
    url: '/base/restapi/euc.account/v1/havana/apply_session',
    method: 'post'
  })
}

//获取当前订单状态

export const getCurrentOrders = (data, params) => {
  params = Object.assign({
    opensite_extra: undefined,
    opensite_come_from: undefined
  }, params)
  data = Object.assign({
    address_id: 0,
    address_select_by: '',
    cinema_deliver_info: null,
    come_from: 'mobile',
    deliver_time: '',
    entities: [[]],
    entities_with_ingredient: [[]],
    geohash: 'wkeztn1j1xwb',
    hongbao_action: 0,
    hongbao_sn: '',
    hongpon_entities: null,
    is_ant_diamond_vip: 1,
    is_pintuan: null,
    merchant_coupon_action: 1,
    merchant_coupon_id: '',
    packages: [[]],
    paymethod_id: -1,
    restaurant_id: '',
    scene_id: -1,
    sig: '',
    sub_channel: 'zebra:offline',
    tying_entities: [],
    user_id: '',
    wechat_unionid: ''
  }, data)
  console.log(data)
  return axios.request({
    url: '/base/restapi/booking/v1/carts/checkout?&opensite_extra='+params.opensite_extra+'&opensite_come_from='+params.opensite_come_from,
    data,
    method: 'post',
    headers: {
      'x-shard': {
        shopid: data.shopId,
        loc: data.lat + ',' + data.lng
      }
    },
    contentType: 'application/json'
  })
}
